package org.example.device.feign.service.impl;

import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.device.feign.convert.DeviceInfoMapperConvert;
import org.example.device.feign.entity.DeviceBaseDTO;
import org.example.device.feign.entity.DeviceInfoDTO;
import org.example.device.feign.service.DeviceRemoteService;
import org.example.device.feign.service.GateWayFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
@Slf4j
public class DeviceFeignServiceImpl implements DeviceRemoteService {
    @Lazy
    @Autowired
    private GateWayFeignService gateWayFeignService;
    private final DeviceInfoMapperConvert deviceInfoMapperConvert;
    @Override
    public DeviceInfoDTO queryDeviceInfo(String groupId) {
        List<DeviceBaseDTO> groupDeviceBase = gateWayFeignService.getGroupDeviceBase(Long.valueOf(groupId));
        if (groupDeviceBase.isEmpty()) {
            return null;
        }
        return deviceInfoMapperConvert.deviceBaseDTO2DeviceInfoDTO(groupDeviceBase.get(0));
    }
}
